/************************************************************
 * Copyright (C), 2022-2030, dina. Co., Ltd.
 * FileName:        form_chart_info.h
 * Author:          Dan Yin
 * Date:            2024-07-22
 * Description:     Display temperature/fluoresence/melting chart info
 * Version:         1.0.0.0
 **********************************************************/

#ifndef FORM_CHART_INFO_H
#define FORM_CHART_INFO_H

// add necessary includes here
#include "ui/defines/global.h"

class ChartInfoThread : public QThread
{
    Q_OBJECT

public:
    // The default constructor
    ChartInfoThread(QObject *parent){
        qDebug() << Q_FUNC_INFO;
        m_pParent = parent;
    }

    // Stop thread
    void stop() { m_bStopped = true; }

    // Default thread function
    void run();

signals:
    // Refresh the fluoresence chart view
    void signalRefreshFluoChart(const QMap<int, QStringList> & mapFluoValues);

private:
    QObject *       m_pParent;
    volatile bool   m_bStopped = false;
};

class FormPlotDlg;

namespace Ui {
class FormChartInfo;
}

class FormChartInfo : public QWidget
{
    Q_OBJECT

public:
    // The default constructor
    explicit FormChartInfo(QWidget *parent = nullptr);

    // The default destructor
    ~FormChartInfo();

    // Display window
    void displayWindow();

    // Get temperature/fluoresence data from chart data
    int getChartData(int nChartType, QMap<unsigned int, QVector<QPointF>> &mapValue);

protected:
    // Triggers an event before it is switch language
    void changeEvent(QEvent *event);

signals:
    // The signal that refresh UI info
    void signalRefreshUI();

private slots:
    void on_pushButton_Cancel_clicked();

    // The slot that refresh UI info
    void slotRefreshUI();

    // Receive a heat value on sample hole
    void slotHeatValueReceived(unsigned int unCanId, QList<float> lstDataValue);

    // Receive a fluoresence value on sample hole
    void slotFluoValueReceived(unsigned int unCanId, const QMap<int, QStringList> & mapFluoValues);

    // Receive a fluoresence value on sample hole
    void slotRefreshFluoChart(const QMap<int, QStringList> & mapFluoValues);

private:
    // Receive a fluoresence value on sample hole
    void recvFluoValue(unsigned int unCanId, const QMap<int, QStringList> & mapFluoValues);

private:
    // After constructing object, initialize the object
    void _initialze();

    // Init the window style
    void _initUi();

private:
    Ui::FormChartInfo *ui;

    QThread                 m_thrTempWorker;
    QThread                 m_thrFluoWorker;
    QThread                 m_thrMeltWorker;

    FormPlotDlg             *m_pTempChartDlg = nullptr;
    FormPlotDlg             *m_pFluoChartDlg = nullptr;
    FormPlotDlg             *m_pMeltChartDlg = nullptr;

    ChartInfoThread         *m_pChartCurvesThread = nullptr;
};

#endif // FORM_CHART_INFO_H
